<!DOCTYPE html>
<html>
<head>
<div th:include="base-libs :: base-libs" />
<title>我的签约患者</title>

<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=UTF-8">

<style>
	.laydate-icon{
		width:87% !important;
		padding-left: 5px;
		line-height: 28px;
		background-color: #fff;
		height: 28px;
		border: 1px solid #B6B6B6;
		border-radius: 5px;
	}
	.spanBtn{
		font-weight: bold;
    	color: blue;
    	cursor:pointer;
	}
</style>
<!--[if IE 8.0]>
<style>
	#SHZT{
		position:relative;
		top:3px;
		line-height:30px;
	}
</style>
<![endif]-->
<script th:inline="javascript">
    /**读取request中的初始化数据*/
    var requestData = [[${requestData}]];
</script>
<script>

    var initKsdm = [{KSDM : "" , KSMC : "全部"}];
    var initYsxm = [{YSGH : "" , XM : "全部"}];
	$(function(){
        initView();
        //$(this).getZydmCache({callback:initData});
        initData();

    })
    
    function initData(){
        if(!requestData["isManager"]){
            $("#combogridYljg").combogrid("grid").datagrid("loadData", [requestData]);
            $("#combogridYljg").combogrid("setValue", requestData);
            initYsAndKs(requestData);
        }
        $("#btnQuery").trigger("click");
	}

    function initView() {
    	//回车查询
    	enterToQuery(btnQueryHandler);

        $('#YJKSDM').combobox({
            height: 30,
            width: 250,
            valueField:'KSDM',
            textField:'KSMC',
            mode : "local",
			data : initKsdm,
            inputCode: 'inputCode', //拼音码
            filter: function(q, row){
                var opts = $(this).combobox('options');
                return row[opts.textField].indexOf(q) == 0;
            },
            onSelect: function(rec){
                if(!StringUtils.isEmpty(rec.KSDM)){
                    var row = $('#combogridYljg').combogrid('grid').datagrid('getSelected');
                    $.QuickRemote.AjaxJson("/console/ksxx/querySecondJgKsxx", function(result){
                        result = initKsdm.concat(result);
                        $("#EJKSDM").createOptions(result,{textField : "KSMC" , valueField : "KSDM" , needNull : false});
                    }, {PTJGID : row.PTJGID , KSDM : rec.KSDM});
				}
            }
        });

        $('#YSGH').combobox({
            height: 30,
            width: 250,
            valueField:'YSGH',
            textField:'XM',
            mode : "local",
			date : initYsxm,
            inputCode: 'inputCode', //拼音码
            filter: function(q, row){
                var opts = $(this).combobox('options');
				return row[opts.textField].indexOf(q) == 0;
            }
        });

        var readonly = !requestData["isManager"];
        $("#combogridYljg").combogrid({
            height: 30
            ,width: 250
            ,panelWidth: 500
            ,singleSelect: true
            ,pagination: true
            ,idField: 'YLJGDM'
            ,textField: 'YLJGMC'
            ,mode: "remote"
            ,readonly: readonly
            ,hasDownArrow: !readonly
            ,url: "/console/yljgxx/queryPageSummary.service"
            ,delay: 1000
            ,reversed: false
            ,columns:[[
                {
                    field:'YLJGMC'
                    ,title:'机构名称'
                    ,width:240
                }
                ,{
                    field:'XZQHMC'
                    ,title:'行政区划'
                    ,width:80
                }
                ,{
                    field:'WSJGLBMC'
                    ,title:'机构类别'
                    ,width:80
                }
                ,{
                    field:'YYDJMC'
                    ,title:'机构等级'
                    ,width:80
                }
            ]]
            ,onBeforeLoad: function(queryParams) {
                var url = $(this).datagrid("options")["url"];
				/*URL不等空时再发送请求*/
                if (!readonly) {
                    queryParams["pageSize"] = queryParams["rows"];
                    queryParams["pageNumber"] = queryParams["page"];
                    queryParams["YLJGMC"] = queryParams["q"];
                    $("#YJKSDM").combobox("clear");
                    $("#YJKSDM").combobox("loadData",initKsdm);
                    $("#YSGH").combobox("clear");
                    $("#YSGH").combobox("loadData",initYsxm);
                    $("#EJKSDM").createOptions(initKsdm,{textField : "KSMC" , valueField : "KSDM" , needNull : false});
                    return true;
                }else{
                    return false;
                }
            },
            onClickRow : function(rowIndex, rowData){
                var queryParams = $.extend({}, rowData);
                initYsAndKs(queryParams);
            },
            onLoadSuccess : function(data){

			}
        });
    	
		$("#qyhzTable").datagrid({
				idField : "HYBH",
				striped : true,
				clickToSelect: true,
				fitColumns: true,
				fit:true,
				scrollbarSize:15,
				singleSelect: true,
				columns : [[
// 						{field : "xz",checkbox:true},
						{field : "YLJGMC",title : "医疗机构名称",width:180, align:'center', formatter : function(value){
                            return '<span title="'+value+'">'+value+'</span>';
						}},
						{field : "YJKSMC",title : "一级科室",width:60, align:'center',formatter:function(value){
//							var reg = /.{8}$/;
//							return value.replace(reg,'********');
							return value;
						}},
						{field : "YSXM",title : "医生姓名",width:60, align:'center'},
						{field : "ZYLXMC",title : "资源类型",width:60, align:'center',formatter:function(value){
								return '<span title="'+value+'">'+value+'</span>';
							}},
						{field : "HYLXMC",title : "号源类型",width:60, align:'center',formatter:function(value){
								return '<span title="'+value+'">'+value+'</span>';
							}},
						{field : "PBRQ",title : "排版日期",width:60, align:'center' , formatter: function(value){
                            return value.substring(0,10);
						}},
						{field : "YYSD",title : "时段",width:40, align:'center'},
						{field : "YYSJD",title : "时间段",width:70, align:'center',formatter:function(value){
							return '<span title="'+value+'">'+value+'</span>';
						}},
						{field : "YYZHYS",title : "医院总号源数",width:60, align:'center'},
						{field : "SYHYS",title : "剩余号源数",width:60, align:'center'},
						{field : "YYYS",title : "已预约数",width:60, align:'center'},
						{field : "HYZT",title : "号源状态",width:40, align:'center'}
				]],
				pagination : true,
				pageList: [10, 20, 50, 100, 200],
				method : "post",
				onBeforeLoad : function(params) {
                    var url = $(this).datagrid("options")["url"];
                    if(!StringUtils.isEmpty(url)){
                        var yljgxx = getQueryFormValue();
                        params = $.extend(params,yljgxx);
//                        var YLJGDM = $("#combogridYljg").combobox("getValue");
                        var YJKSDM = $("#YJKSDM").combobox("getValue");
                        var YSGH = $("#YSGH").combobox("getValue");
//                        params["YLJGDM"] = YLJGDM;
                        params["YJKSDM"] = YJKSDM;
                        params["YSGH"] = YSGH;
                        getContainerDataByClassName('conditionBox','condition',params);//查询条件
						return true;
					}else{
                        return false;
                    }
				},
				onClickRow : function(rowIndex, rowData){

				},
				onLoadSuccess: function(data){
// 					alert(JSON.stringify(data))
 				}
			});


		
		//查询开始时间设置
		var startTimeObj = {
			 elem: '#PBRQ_START',
		  	 choose: function(datas){
		  		endTimeObj.min = datas;
		  	 }
		};
		laydate(startTimeObj);
		
		//查询结束时间设置
		var endTimeObj = {
				elem: '#PBRQ_END',
			  	choose: function(datas){
			  		startTimeObj.max = datas;
			    }
		};	
		laydate(endTimeObj);
	}

	/** 初始化医生与一级科室下拉框 */
	function initYsAndKs(params){
        $.QuickRemote.AjaxJson("/console/ksxx/", function(result){
            result = initKsdm.concat(result);
            $("#YJKSDM").combobox("loadData",result);
        }, params);

        $.QuickRemote.AjaxJson("/console/yljgry/queryYljgryById", function(result){
            result = initYsxm.concat(result);
            $("#YSGH").combobox("loadData",result);
        }, params);
	}

    /**获取查询表单的值*/
    function getQueryFormValue() {
        var params = {};
        var item = $("#combogridYljg").combogrid("grid").datagrid("getSelected");
        if(item){
            params["YLJGDM"] = item["YLJGDM"];
        }else{
            params["YLJGMC"] = $("#combogridYljg").combogrid("getText");
        }
        //params["KSMC"] = $("#KSMC").val();
        return params;
    }


   	/** 查询  */
   	function btnQueryHandler(){
   		$("#qyhzTable").datagrid({"url":"pageQueryAll.service"});
   	}
   	
   	/** 导出 */
   	function download(){
        var params = getQueryFormValue();
        if(params["YLJGDM"]){
			$("#YLJGDM").attr("name" , "YLJGDM").val(params["YLJGDM"]);
		}
   		$("#downloadForm").submit();
   	}
   	
</script>

</head>

<body>
	<div class="easyui-layout" fit="true" border="false">
		<div region="north" style="overflow:hidden;padding:15px 0px;background:#f9f9f9" border="false">
			<form action="queryAllForExcel.service" method="post" enctype="multipart/form-data" id="downloadForm" >
				<table class="form-table" id="conditionBox">
					<tr>
						<td class="td-text">所属医院：</td>
						<td class="td-content" >
							<input id="YLJGDM" hidden="hidden" >
							<input id="combogridYljg"/>
						</td>
						<td class="td-text">所属科室：</td>
						<td class="td-content">
							<select id="YJKSDM" name="YJKSDM" class="form-control condition easyui-combobox" style="width: 100%;">
								<option value="">全部</option>
							</select>
						</td>
						<td class="td-text">所属专科：</td>
						<td class="td-content">
							<select id="EJKSDM" name="EJKSDM" class="form-control condition" style="width: 100%;">
								<option value="">全部</option>
							</select>
						</td>
						<td class="td-text" style="width:175px;text-align:center">
							<button id="btnQuery" class="btn btn-info" type="button" onclick="btnQueryHandler()">查询</button>
							<button type="button" onclick="download()">导出</button>
						</td>
					</tr>
					<tr class="activeQuery">
						<td class="td-text">医生：</td>
						<td class="td-content">
							<select id="YSGH" name="YSGH" class="form-control condition easyui-combobox" style="width: 100%;">
								<option value="">请选择</option>
							</select>
						</td>
						<td class="td-text">开始日期：</td>
						<td class="td-content">
						<input name="PBRQ_START" id="PBRQ_START" class="laydate-icon condition" />
						</td>
						<td class="td-text">结束日期：</td>
						<td class="td-content">
						<input name="PBRQ_END" id="PBRQ_END" class="laydate-icon condition" />
						</td>
						<td class="td-text"></td>
					</tr>
				</table>
			</form>
			<!--<div style="margin-top:10px;">
				&nbsp;&nbsp;&nbsp;&nbsp;
				<button type="button" onclick="">门诊预约</button>
				<button type="button" onclick="forwardSzxt('mz')">门诊转诊</button>
				<button type="button" onclick="forwardSzxt('zy')">住院转诊</button>
			</div>-->
		</div>
		<div region="center" border="false">
			<table id="qyhzTable" border="false"></table>
		</div>
	</div>
	
</body>
</html>
